﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;


namespace zlh.Studentyemian
{
    public partial class stumimaxiugai : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["color"] == "1")
            {
                Page.Theme = "1";

            }
            else if (Session["color"] == "2")
            {
                Page.Theme = "2";
            }
            else
            {
                Page.Theme = "3";
            }
        }

        protected void xiugaibtn_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112130;uid=2014112130;pwd=19970514";
            SqlConnection conn = new SqlConnection(strCn);

            try
            {
                conn.Open();
                string strsql = "select * from StudentLogin where StudentId='" + this.adminName.Text + "'and StudentPassword='" + this.adminPSW.Text + "'";
                SqlCommand cmd = new SqlCommand(strsql, conn);
                SqlDataReader sdr = cmd.ExecuteReader();
                if (sdr.Read())
                {
                    sdr.Close();
                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    SqlStringBuilder.Append("UPDATE  StudentLogin ");
                    SqlStringBuilder.AppendFormat("SET         StudentPassword = N'{0}' ", this.adminnewPSW.Text);
                    SqlStringBuilder.AppendFormat("WHERE   (StudentId = N'{0}') ", this.adminName.Text);
                    string strsql2 = SqlStringBuilder.ToString();
                    SqlCommand cmd2 = new SqlCommand(strsql2, conn);

                    int i = cmd2.ExecuteNonQuery();
                    if (i < 1)
                    {
                        this.lblInfo.Text = "密码修改失败！";

                    }
                    else
                    {
                        this.lblInfo.Text = "密码修改成功！";
                    }
                }
                else
                {
                    this.lblInfo.Text = "您输入的原密码错误，检查后重新输入！";
                }


            }
            catch (System.Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                conn.Close();
            }

        }
    }
}